package leetcode.easy.q58;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Q {
    public static void main(String[] args) {

    }
}

class Solution {
     public int lengthOfLastWord(String s) {
         boolean word=false;
         int len=0;
         for(int i=s.length()-1;i>=0;i--){
             char c=s.charAt(i);
             if(c!=' '){
                 word=true;
                 len++;
             }else if(word){
                 break;
             }
         }
         return len;
     }


}
class Solution2 {
    public int lengthOfLastWord(String s) {
        String s1 = s.trim();
        int length = s1.length();
        int lastStart = s1.lastIndexOf(" ") + 1;
        return length - lastStart;
    }
}